using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using Net.SourceForge.WURFL.Core;

namespace Roaming.view
{
    public partial class infoDetails : System.Web.UI.Page
    {
        protected int iArtId = 0;
        protected int iParId = 0;
        protected DataSet dsArticle = null;
        protected int cols = 3;
        protected DataSet dsOtherArticles = null;
        protected DataSet dsCate = null;
        protected string Infopage = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            string strUA = Request.Headers["USER-AGENT"].ToString();
            if (strUA.ToLower().Contains("opera"))
            {
                if (Request.Headers["X-OperaMini-Phone-UA"] != null)
                    strUA = Request.Headers["X-OperaMini-Phone-UA"].ToString();
            }
            cols = DAL.getColLinkSite(strUA);
            if (cols > 2)
            {
                cols = 3;
            }
            try
            {
                Infopage = Session["Infopage"].ToString();
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            if ((Request.QueryString["artId"] != null) && (Request.QueryString["artId"].ToString() != ""))
                iArtId = Int32.Parse(Request.QueryString["artId"].ToString());
            BindParentID(iArtId);
            if (!Page.IsPostBack)
            {
                if (iArtId > 0)
                    BindDataById(iArtId);
            }
        }
        protected void BindParentID(int iArtId)
        {
            string strSQL = string.Format("exec tblCategory_GetById {0}", iArtId);
            DataSet dsParentID = DAL.GetDataSet(strSQL);
            if (dsParentID.Tables[0].Rows.Count > 0)
            {
                iParId = Int32.Parse(dsParentID.Tables[0].Rows[0]["parentId"].ToString());
            }
            dsParentID.Dispose();
        }
        protected string getTopByCate_img(string tmp)
        {
            string strSQL = string.Format("exec tblWeatherIcon_GetByKey '{0}'", tmp);
            DataSet ds = Common.DAL.GetDataSet(strSQL);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["Img"].ToString();
               
            }
            else
                return "";

        }
        protected void BindDataById(int iArtId)
        {
            string strSQL1="";
            if (iParId == 92)
            {
                strSQL1 = string.Format("exec tblArticle_GetTopNByCateId {0},{1}", 0, iArtId);
            }
            else
            strSQL1 = string.Format("exec tblArticle_GetById {0}", iArtId);
            dsArticle = DAL.GetDataSet(strSQL1);
            if (dsArticle.Tables[0].Rows.Count > 0)
            {
                string strSQL2 = "";
                strSQL2 = string.Format("exec tblCategory_GetById {0}", Int32.Parse(dsArticle.Tables[0].Rows[0]["categoryId"].ToString()));
                
                dsCate = DAL.GetDataSet(strSQL2);
                string strSQL4 = "";
                if (iParId == 92)
                {
                    strSQL4 = string.Format("exec tblArticle_GetTopNAndCondition {0},N'{1}'", 3, "AND status=1 AND categoryId in (select categoryId from tblCategory where parentId=92) AND articleId < " + dsArticle.Tables[0].Rows[0]["articleId"].ToString());

                }
                else
                strSQL4 = string.Format("exec tblArticle_GetTopNAndCondition {0},N'{1}'", 3, "AND status=1 AND categoryId=" + dsArticle.Tables[0].Rows[0]["categoryId"].ToString() + " AND articleId < " + dsArticle.Tables[0].Rows[0]["articleId"].ToString());
                dsOtherArticles = DAL.GetDataSet(strSQL4);
                rptOtherArticles.DataSource = dsOtherArticles;
                rptOtherArticles.DataBind();
                rptOtherArticles.Dispose();
            }
            dsArticle.Dispose();
            dsOtherArticles.Dispose();
        }
    }
}
